package FlyGame;

import org.junit.Test;

import javax.sound.sampled.*;
import java.io.IOException;
import java.io.InputStream;

public class BGM {
    public static Clip clip;
    public static AudioInputStream ios;

    public void play(){
        try {
            clip = AudioSystem.getClip();
        } catch (LineUnavailableException e) {
            e.printStackTrace();
        }
        InputStream in = BGM.class.getResourceAsStream("/statics/bgm.wav");

        if( in != null){
            try {
                ios = AudioSystem.getAudioInputStream(in);
            } catch (UnsupportedAudioFileException | IOException e) {
                e.printStackTrace();
            }
        }
        try {
            clip.open(ios);
        } catch (LineUnavailableException | IOException e) {
            e.printStackTrace();
        }
        clip.start();
        clip.loop(Clip.LOOP_CONTINUOUSLY);
    }

    public void stop(){
        clip.close();
    }

    @Test
    public void test(){
        BGM bgm = new BGM();
        bgm.play();

    }
}
